{extend name="base/base" /}
{block name="content"}
  <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <div class="layui-tab-content">
      <div class="layui-tab-item layui-show">
        <form class="layui-form" id="edit_form" onsubmit="return false">
          <div class="layui-form-item">
            <label class="layui-form-label">管理员：</label>
            <div class="layui-input-inline">
              <input name="name" required="" lay-verify="required" autocomplete="off" class="layui-input" type="text" value="{$user_info.name}">
            </div>
            <div class="layui-form-mid layui-word-aux"></div> 
          </div>
          <!-- <div class="layui-form-item">
            <label class="layui-form-label">头像：</label>
            <div class="layui-input-inline">
                <img src="{$user_info.pic}" style="width: 100px;height: 100px" id="show_upload_img">
                <input type="hidden" name="pic" id='pic' value="{$user_info.pic}">
             </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button type="button" class="layui-btn" id="upload">
                <i class="layui-icon"></i>上传图片
              </button>
            </div>
          </div> -->
          <div class="layui-form-item">
            <label class="layui-form-label">登录密码：</label>
            <div class="layui-input-inline">
              <input name="password" lay-vertype="tips" placeholder="请输入密码" autocomplete="off" class="layui-input" type="password">
            </div>
            <div class="layui-form-mid layui-word-aux">英文和数字组合</div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button class="layui-btn" onclick="ajax()" lay-filter="formDemo">修改资料</button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div> 
{/block}
{block name="script"}
<script>
    layui.use('upload', function(){
      var upload = layui.upload;
      upload.render({
      elem: '#upload'
      ,url: '{:C("system_url")}/api/Upload/upload_img'
      ,before:function(){
        var index = layer.msg('正在拼命处理...' , {
          icon: 16 ,
          shade: 0.6 ,
          time: 0 ,
        });
      }
      ,done: function(res){
        if(res.code==0){
          $("#show_upload_img").attr('src',res.data);
          $("#pic").val(res.data);
          layer.msg('上传图片成功');
        } else {
          layer.msg('上传图片失败');
        }
      }
      });      
    });

    function ajax(){
      var post_data = $("#edit_form").serialize();
      $.ajax({
          url:"{:url('admin/admin/edit')}",
          type:"POST",
          data:post_data,
          success:function(ret){
              if (ret.code == 0) {
                layer.msg('修改成功');
                window.location.reload();
              }
              if (ret.code == 1) {
                  layer.msg(ret.msg);
              }
          }
      });
    }
</script>
{/block}
